<template>
	<view>
		<button class="avatar-wrapper" type="primary" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
			<image class="avatar" :src="avatarUrl"></image>
			头像
		</button>
	</view>
</template>

<script setup lang="ts">
import { ref } from 'vue';
const avatarUrl = ref<string | null>(null);

async function onChooseAvatar(value: any) {
	let img = value.detail.avatarUrl as string;
	avatarUrl.value = img;
	let code = await Login();
	console.log(code);
}

function Login() {
	return new Promise((res: any, err: any) => {
		uni.login({
			success: (e: any) => {
				res(e.code);
			},
			fail: (e: any) => {
				err(e);
			}
		});
	});
}
</script>

<style></style>
